package com.roncoo.student.stu.controller;


import com.roncoo.student.stu.entity.UserFavorites;
import com.roncoo.student.stu.service.IUserFavoritesService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jl
 * @since 2021-04-09
 */
@RestController
@RequestMapping("/stu/user-favorites")
public class UserFavoritesController {

     @Resource
    private IUserFavoritesService favoritesService;


     @PostMapping("findAll")
    public List<UserFavorites> findAll(Integer userId){
         return favoritesService.findAll(userId);
     }

     @PostMapping("findUserAndCourse")
     public boolean findUserAndCourse(Integer userId,Integer courseNo){
         return favoritesService.findUserAndCourse(userId,courseNo);
     }


    /**
     * 添加收藏
     * @param userFavorites
     * @return boolean
     */
    @PostMapping("addFavorites")
    public boolean addFavorites(UserFavorites userFavorites){
        userFavorites.setFavTime(LocalDate.now());
        return favoritesService.save(userFavorites);
    }

    /**
     *
     * @param id
     * @return Boolean
     */
     @PostMapping("del")
    public Boolean del(Integer id){
         return favoritesService.removeById(id);
    }
}

